﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using Model.Linqtosql;
using System.Data.OleDb;
using System.Data;
using ExtAspNet;
namespace HealthSystem.sysAdmin
{
    public partial class standerd_New : BasePage
    {
        DataDataContext data = LinqFactory.CreateInstance();
        protected void Page_Init(object sender, EventArgs e)
        {
            string standardcode = Request["standardcode"];
            InitGrid(standardcode);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlstarBind();
                string standardcode = Request["standardcode"];
                if (!string.IsNullOrEmpty(standardcode))
                {
                    ddlstar.SelectedValue = standardcode;
                }
            }
            
        }
        private void ddlstarBind()
        {
            ddlstar.Items.Add("身高", "height");
            ddlstar.Items.Add("体重", "weight");
            ddlstar.Items.Add("胸围", "chest");
            ddlstar.Items.Add("肺活量", "lungs");
            ddlstar.Items.Add("营养", "nutrition");
            ddlstar.Items.Add("脉搏", "pulsation");

        }
        //protected void btnimport_Click(object sender, EventArgs e)
        //{
        //    DataSet ds = new DataSet();
        //    Model.Linqtosql.standard_chest chest = null; ;
        //    List<Model.Linqtosql.standard_chest> chests = new List<Model.Linqtosql.standard_chest>();
        //    if (txtimport.HasFile && !String.IsNullOrEmpty(txtimport.FileName))
        //    {
        //        String sfile = txtimport.FileName;
        //        if (sfile.ToLower().EndsWith(".xls") || sfile.ToLower().EndsWith(".xlsx"))
        //        {
        //            try
        //            {
        //                var importpath = Server.MapPath("~/temp/import/");
        //                if (!System.IO.Directory.Exists(importpath))
        //                    System.IO.Directory.CreateDirectory(importpath);
        //                txtimport.SaveAs(importpath + sfile);
        //                ds = ImportExcel(importpath + sfile);
        //                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //                {
        //                    chest = new Model.Linqtosql.standard_chest();
        //                    if (ds.Tables[0].Rows[i]["年龄"] == null)
        //                    {
        //                        Alert.Show("第" + i + "行年龄不对,请检查！");
        //                        return;
        //                    }
        //                    else
        //                    {
        //                        chest.age = Convert.ToInt16(ds.Tables[0].Rows[i]["年龄"]);
        //                    }
        //                    if (ds.Tables[0].Rows[i]["性别"] == null)
        //                    {
        //                        Alert.Show("第" + i + "行性别不对,请检查！");
        //                        return;
        //                    }
        //                    else
        //                    {
        //                        chest.sex = ds.Tables[0].Rows[i]["性别"].ToString();
        //                    }
        //                    if (ds.Tables[0].Rows[i]["p10"] == null)
        //                    {
        //                        Alert.Show("第" + i + "行p10不对,请检查！");
        //                        return;
        //                    }
        //                    else
        //                    {
        //                        chest.p10 = Convert.ToDecimal(ds.Tables[0].Rows[i]["p10"]);
        //                    }
        //                    if (ds.Tables[0].Rows[i]["p25"] == null)
        //                    {
        //                        Alert.Show("第" + i + "行p25不对,请检查！");
        //                        return;
        //                    }
        //                    else
        //                    {
        //                        chest.p25 = Convert.ToDecimal(ds.Tables[0].Rows[i]["p25"]);
        //                    }
        //                    if (ds.Tables[0].Rows[i]["p75"] == null)
        //                    {
        //                        Alert.Show("第" + i + "行p75不对,请检查！");
        //                        return;
        //                    }
        //                    else
        //                    {
        //                        chest.p75 = Convert.ToDecimal(ds.Tables[0].Rows[i]["p75"]);
        //                    }
        //                    if (ds.Tables[0].Rows[i]["p90"] == null)
        //                    {
        //                        Alert.Show("第" + i + "行p90不对,请检查！");
        //                        return;
        //                    }
        //                    else
        //                    {
        //                        chest.p90 = Convert.ToDecimal(ds.Tables[0].Rows[i]["p90"]);
        //                    }
        //                    if (ds.Tables[0].Rows[i]["版本"] == null)
        //                    {
        //                        Alert.Show("第" + i + "行版本不对,请检查！");
        //                        return;
        //                    }
        //                    else
        //                    {
        //                        chest.version = ds.Tables[0].Rows[i]["版本"].ToString();
        //                    }
        //                    chests.Add(chest);
        //                }
        //                var versions = chests.Select(p => p.version).Distinct().ToList();
        //                if (versions.Count != 1)
        //                {
        //                    Alert.Show("Excel中只能存在一种标准，请检查！");
        //                    return;
        //                }
        //                //using (TransactionScope scope = new TransactionScope())
        //                //{
        //                var m = data.standard_chest.Where(p => p.version == versions[0]).ToList();
        //                data.standard_chest.DeleteAllOnSubmit(m);
        //                data.SubmitChanges();
        //                data.standard_chest.InsertAllOnSubmit(chests);
        //                data.SubmitChanges();
        //                //scope.Complete();
        //                //}
        //            }
        //            catch (Exception ex)
        //            {
        //                Alert.Show(ex.Message);
        //                return;
        //            }
        //        }
        //    }
        //    else
        //    {
        //        ExtAspNet.Alert.Show("请浏览需要导入的文件");
        //    }

        //}
        protected void btnimport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            if (txtimport.HasFile && !String.IsNullOrEmpty(txtimport.FileName))
            {
                String sfile = txtimport.FileName;
                sfile = System.IO.Path.GetFileName(sfile);
                if (sfile.ToLower().EndsWith(".xls") || sfile.ToLower().EndsWith(".xlsx"))
                {
                    string star = ddlstar.SelectedText;
                    if (!sfile.Contains(star))
                    {
                        Alert.Show("您现在要升级的是"+star+"标准,请确认无误，保证你要导入的文件名中包含"+star+"如："+star+"标准.xls");
                        return;
                    }
                    try
                    {
                        var importpath = Server.MapPath("~/temp/import/");
                        if (!System.IO.Directory.Exists(importpath))
                            System.IO.Directory.CreateDirectory(importpath);
                        txtimport.SaveAs(importpath + sfile);
                        ds = ImportExcel(importpath + sfile);
                        ViewState["stardardata"] = ds.Tables[0];
                        Grid1.DataSource = ds.Tables[0];
                        Grid1.DataBind();
                       
                        
                    }
                    catch (Exception ex)
                    {
                        Alert.Show(ex.Message);
                        return;
                    }
                }
            }
            else
            {
                ExtAspNet.Alert.Show("请浏览需要导入的文件");
            }

        }
        //private bool CheckBaseStard(DataTable dt)
        //{

        //}
        //private void ImportHandle()
        //{
        //    String stardar = this.ddlstar.SelectedValue;
        //    ExtAspNet.Grid Grid1 = new Grid();
        //    ExtAspNet.BoundField bf;
        //    switch (stardar)
        //    {
        //        case "height":
        //            bf=new ExtAspNet.BoundField ();
        //            bf.DataField="age";
        //            bf.HeaderText="年龄";
        //            Grid1.Columns.Add(bf);

        //            bf=new ExtAspNet.BoundField ();
        //            bf.DataField = "sex";
        //            bf.HeaderText="性别";
        //            Grid1.Columns.Add(bf);

        //            bf=new ExtAspNet.BoundField ();
        //            bf.DataField = "p10";
        //            bf.HeaderText = "p10";
        //            Grid1.Columns.Add(bf);

        //            bf=new ExtAspNet.BoundField ();
        //            bf.DataField = "p25";
        //            bf.HeaderText = "p25";
        //            Grid1.Columns.Add(bf);

        //            bf=new ExtAspNet.BoundField ();
        //            bf.DataField = "p75";
        //            bf.HeaderText = "p75";
        //            Grid1.Columns.Add(bf);

        //            bf=new ExtAspNet.BoundField ();
        //            bf.DataField = "p90";
        //            bf.HeaderText = "p90";
        //            Grid1.Columns.Add(bf);

        //            bf=new ExtAspNet.BoundField ();
        //            bf.DataField = "version";
        //            bf.HeaderText="版本";
        //            Grid1.Columns.Add(bf);

        //    }
        //}
        private List<Model.Linqtosql.standard_chest> ChestDataTableToList(DataTable dt)
        {
            Model.Linqtosql.standard_chest chest = null;
            List<Model.Linqtosql.standard_chest> chests = new List<Model.Linqtosql.standard_chest>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                chest = new Model.Linqtosql.standard_chest();
                chest.id = Guid.NewGuid().ToString();
                if (dt.Rows[i]["年龄"] == null)
                {
                    Alert.Show("第" + i + "行年龄不对,请检查！");
                    return null;
                }
                else
                {
                    chest.age = Convert.ToInt16(dt.Rows[i]["年龄"]);
                }
                if (dt.Rows[i]["性别"] == null)
                {
                    Alert.Show("第" + i + "行性别不对,请检查！");
                    return null;
                }
                else
                {
                    chest.sex = dt.Rows[i]["性别"].ToString();
                }
                if (dt.Rows[i]["p10"] == null)
                {
                    Alert.Show("第" + i + "行p10不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p10 = Convert.ToDecimal(dt.Rows[i]["p10"]);
                }
                if (dt.Rows[i]["p25"] == null)
                {
                    Alert.Show("第" + i + "行p25不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p25 = Convert.ToDecimal(dt.Rows[i]["p25"]);
                }
                if (dt.Rows[i]["p75"] == null)
                {
                    Alert.Show("第" + i + "行p75不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p75 = Convert.ToDecimal(dt.Rows[i]["p75"]);
                }
                if (dt.Rows[i]["p90"] == null)
                {
                    Alert.Show("第" + i + "行p90不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p90 = Convert.ToDecimal(dt.Rows[i]["p90"]);
                }
                if (dt.Rows[i]["版本"] == null)
                {
                    Alert.Show("第" + i + "行版本不对,请检查！");
                    return null;
                }
                else
                {
                    chest.version = dt.Rows[i]["版本"].ToString();
                }
                chests.Add(chest);
            }
            return chests;
        }
        private List<Model.Linqtosql.standard_height> HeightDataTableToList(DataTable dt)
        {
            Model.Linqtosql.standard_height chest = null;
            List<Model.Linqtosql.standard_height> chests = new List<Model.Linqtosql.standard_height>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                chest = new Model.Linqtosql.standard_height();
                chest.id = Guid.NewGuid().ToString();
                if (dt.Rows[i]["年龄"] == null)
                {
                    Alert.Show("第" + i + "行年龄不对,请检查！");
                    return null;
                }
                else
                {
                    chest.age = Convert.ToInt16(dt.Rows[i]["年龄"]);
                }
                if (dt.Rows[i]["性别"] == null)
                {
                    Alert.Show("第" + i + "行性别不对,请检查！");
                    return null;
                }
                else
                {
                    chest.sex = dt.Rows[i]["性别"].ToString();
                }
                if (dt.Rows[i]["p10"] == null)
                {
                    Alert.Show("第" + i + "行p10不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p10 = Convert.ToDecimal(dt.Rows[i]["p10"]);
                }
                if (dt.Rows[i]["p25"] == null)
                {
                    Alert.Show("第" + i + "行p25不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p25 = Convert.ToDecimal(dt.Rows[i]["p25"]);
                }
                if (dt.Rows[i]["p75"] == null)
                {
                    Alert.Show("第" + i + "行p75不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p75 = Convert.ToDecimal(dt.Rows[i]["p75"]);
                }
                if (dt.Rows[i]["p90"] == null)
                {
                    Alert.Show("第" + i + "行p90不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p90 = Convert.ToDecimal(dt.Rows[i]["p90"]);
                }
                if (dt.Rows[i]["版本"] == null)
                {
                    Alert.Show("第" + i + "行版本不对,请检查！");
                    return null;
                }
                else
                {
                    chest.version = dt.Rows[i]["版本"].ToString();
                }
                chests.Add(chest);
            }
            return chests;
        }
        private List<Model.Linqtosql.standard_weight> WeightDataTableToList(DataTable dt)
        {
            Model.Linqtosql.standard_weight chest = null;
            List<Model.Linqtosql.standard_weight> chests = new List<Model.Linqtosql.standard_weight>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                chest = new Model.Linqtosql.standard_weight();
                chest.id = Guid.NewGuid().ToString();
                if (dt.Rows[i]["年龄"] == null)
                {
                    Alert.Show("第" + i + "行年龄不对,请检查！");
                    return null;
                }
                else
                {
                    chest.age = Convert.ToInt16(dt.Rows[i]["年龄"]);
                }
                if (dt.Rows[i]["性别"] == null)
                {
                    Alert.Show("第" + i + "行性别不对,请检查！");
                    return null;
                }
                else
                {
                    chest.sex = dt.Rows[i]["性别"].ToString();
                }
                if (dt.Rows[i]["p10"] == null)
                {
                    Alert.Show("第" + i + "行p10不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p10 = Convert.ToDecimal(dt.Rows[i]["p10"]);
                }
                if (dt.Rows[i]["p25"] == null)
                {
                    Alert.Show("第" + i + "行p25不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p25 = Convert.ToDecimal(dt.Rows[i]["p25"]);
                }
                if (dt.Rows[i]["p75"] == null)
                {
                    Alert.Show("第" + i + "行p75不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p75 = Convert.ToDecimal(dt.Rows[i]["p75"]);
                }
                if (dt.Rows[i]["p90"] == null)
                {
                    Alert.Show("第" + i + "行p90不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p90 = Convert.ToDecimal(dt.Rows[i]["p90"]);
                }
                if (dt.Rows[i]["版本"] == null)
                {
                    Alert.Show("第" + i + "行版本不对,请检查！");
                    return null;
                }
                else
                {
                    chest.version = dt.Rows[i]["版本"].ToString();
                }
                chests.Add(chest);
            }
            return chests;
        }
        private List<Model.Linqtosql.standard_lungs> LungsDataTableToList(DataTable dt)
        {
            Model.Linqtosql.standard_lungs chest = null;
            List<Model.Linqtosql.standard_lungs> chests = new List<Model.Linqtosql.standard_lungs>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                chest = new Model.Linqtosql.standard_lungs();
                chest.id = Guid.NewGuid().ToString();
                if (dt.Rows[i]["年龄"] == null)
                {
                    Alert.Show("第" + i + "行年龄不对,请检查！");
                    return null;
                }
                else
                {
                    chest.age = Convert.ToInt16(dt.Rows[i]["年龄"]);
                }
                if (dt.Rows[i]["性别"] == null)
                {
                    Alert.Show("第" + i + "行性别不对,请检查！");
                    return null;
                }
                else
                {
                    chest.sex = dt.Rows[i]["性别"].ToString();
                }
                if (dt.Rows[i]["p10"] == null)
                {
                    Alert.Show("第" + i + "行p10不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p10 = Convert.ToDecimal(dt.Rows[i]["p10"]);
                }
                if (dt.Rows[i]["p25"] == null)
                {
                    Alert.Show("第" + i + "行p25不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p25 = Convert.ToDecimal(dt.Rows[i]["p25"]);
                }
                if (dt.Rows[i]["p75"] == null)
                {
                    Alert.Show("第" + i + "行p75不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p75 = Convert.ToDecimal(dt.Rows[i]["p75"]);
                }
                if (dt.Rows[i]["p90"] == null)
                {
                    Alert.Show("第" + i + "行p90不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p90 = Convert.ToDecimal(dt.Rows[i]["p90"]);
                }
                if (dt.Rows[i]["版本"] == null)
                {
                    Alert.Show("第" + i + "行版本不对,请检查！");
                    return null;
                }
                else
                {
                    chest.version = dt.Rows[i]["版本"].ToString();
                }
                chests.Add(chest);
            }
            return chests;
        }
        private List<Model.Linqtosql.standard_pulsation> PulsationDataTableToList(DataTable dt)
        {
            Model.Linqtosql.standard_pulsation chest = null;
            List<Model.Linqtosql.standard_pulsation> chests = new List<Model.Linqtosql.standard_pulsation>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                chest = new Model.Linqtosql.standard_pulsation();
                chest.id = Guid.NewGuid().ToString();
                if (dt.Rows[i]["年龄"] == null)
                {
                    Alert.Show("第" + i + "行年龄不对,请检查！");
                    return null;
                }
                else
                {
                    chest.age = Convert.ToInt16(dt.Rows[i]["年龄"]);
                }
                if (dt.Rows[i]["性别"] == null)
                {
                    Alert.Show("第" + i + "行性别不对,请检查！");
                    return null;
                }
                else
                {
                    chest.sex = dt.Rows[i]["性别"].ToString();
                }
                if (dt.Rows[i]["p10"] == null)
                {
                    Alert.Show("第" + i + "行p10不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p10 = Convert.ToDecimal(dt.Rows[i]["p10"]);
                }
                if (dt.Rows[i]["p25"] == null)
                {
                    Alert.Show("第" + i + "行p25不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p25 = Convert.ToDecimal(dt.Rows[i]["p25"]);
                }
                if (dt.Rows[i]["p75"] == null)
                {
                    Alert.Show("第" + i + "行p75不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p75 = Convert.ToDecimal(dt.Rows[i]["p75"]);
                }
                if (dt.Rows[i]["p90"] == null)
                {
                    Alert.Show("第" + i + "行p90不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p90 = Convert.ToDecimal(dt.Rows[i]["p90"]);
                }
                if (dt.Rows[i]["版本"] == null)
                {
                    Alert.Show("第" + i + "行版本不对,请检查！");
                    return null;
                }
                else
                {
                    chest.version = dt.Rows[i]["版本"].ToString();
                }
                chests.Add(chest);
            }
            return chests;
        }
        private List<Model.Linqtosql.standard_nutrition> NutritionDataTableToList(DataTable dt)
        {
            Model.Linqtosql.standard_nutrition chest = null;
            List<Model.Linqtosql.standard_nutrition> chests = new List<Model.Linqtosql.standard_nutrition>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                chest = new Model.Linqtosql.standard_nutrition();
                chest.id = Guid.NewGuid().ToString();
                if (dt.Rows[i]["年级"] == null)
                {
                    Alert.Show("第" + i + "行年级不对,请检查！");
                    return null;
                }
                else
                {
                    chest.grade = Convert.ToInt16(dt.Rows[i]["年级"]);
                }
                if (dt.Rows[i]["身高"] == null)
                {
                    Alert.Show("第" + i + "行身高不对,请检查！");
                    return null;
                }
                else
                {
                    chest.sg = Convert.ToInt16(dt.Rows[i]["身高"]);
                }
                if (dt.Rows[i]["性别"] == null)
                {
                    Alert.Show("第" + i + "行性别不对,请检查！");
                    return null;
                }
                else
                {
                    chest.sex = dt.Rows[i]["性别"].ToString();
                }
                if (dt.Rows[i]["p10"] == null)
                {
                    Alert.Show("第" + i + "行p10不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p10 = Convert.ToDecimal(dt.Rows[i]["p10"]);
                }
                if (dt.Rows[i]["p25"] == null)
                {
                    Alert.Show("第" + i + "行p25不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p25 = Convert.ToDecimal(dt.Rows[i]["p25"]);
                }
                if (dt.Rows[i]["p75"] == null)
                {
                    Alert.Show("第" + i + "行p75不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p75 = Convert.ToDecimal(dt.Rows[i]["p75"]);
                }
                if (dt.Rows[i]["p90"] == null)
                {
                    Alert.Show("第" + i + "行p90不对,请检查！");
                    return null;
                }
                else
                {
                    chest.p90 = Convert.ToDecimal(dt.Rows[i]["p90"]);
                }
                if (dt.Rows[i]["版本"] == null)
                {
                    Alert.Show("第" + i + "行版本不对,请检查！");
                    return null;
                }
                else
                {
                    chest.version = dt.Rows[i]["版本"].ToString();
                }
                chests.Add(chest);
            }
            return chests;
        }
        private void InitGrid(string stardarcode)
        {
            if (stardarcode == "nutrition")
            {
                ExtAspNet.BoundField bfgrade = new ExtAspNet.BoundField();
                bfgrade.HeaderText = "年级";
                bfgrade.DataField = "年级";
                Grid1.Columns.Insert(0,bfgrade);

                ExtAspNet.BoundField bfsg = new ExtAspNet.BoundField();
                bfsg.HeaderText = "身高";
                bfsg.DataField = "身高";
                Grid1.Columns.Insert(1, bfsg);
            }
            else
            {
                ExtAspNet.BoundField bfage = new ExtAspNet.BoundField();
                bfage.HeaderText = "年龄";
                bfage.DataField = "年龄";
                Grid1.Columns.Insert(0, bfage);
            }
            ExtAspNet.BoundField bfsex = new ExtAspNet.BoundField();
            bfsex.HeaderText = "性别";
            bfsex.DataField = "性别";
            Grid1.Columns.Add(bfsex);

            ExtAspNet.BoundField bfp10 = new ExtAspNet.BoundField();
            bfp10.HeaderText = "p10";
            bfp10.DataField = "p10";
            Grid1.Columns.Add(bfp10);

            ExtAspNet.BoundField bfp25 = new ExtAspNet.BoundField();
            bfp25.HeaderText = "p25";
            bfp25.DataField = "p25";
            Grid1.Columns.Add(bfp25);

            ExtAspNet.BoundField bfp75 = new ExtAspNet.BoundField();
            bfp75.HeaderText = "p75";
            bfp75.DataField = "p75";
            Grid1.Columns.Add(bfp75);

            ExtAspNet.BoundField bfp90 = new ExtAspNet.BoundField();
            bfp90.HeaderText = "p90";
            bfp90.DataField = "p90";
            Grid1.Columns.Add(bfp90);

            ExtAspNet.BoundField bfversion = new ExtAspNet.BoundField();
            bfversion.HeaderText = "版本";
            bfversion.DataField = "版本";
            Grid1.Columns.Add(bfversion);
        }
        private void ChestInsert(DataTable dt)
        {
            var chests = ChestDataTableToList(dt);
            var chestversions = chests.Select(p => p.version).Distinct().ToList();
            if (chestversions.Count() != 1)
            {
                Alert.Show("Excel中存在多个版本，请修正");
                return;
            }
            var chestquery = data.standard_chest.Where(p => p.version == chestversions[0]).ToList();
            data.standard_chest.DeleteAllOnSubmit(chestquery);
            data.SubmitChanges();
            data.standard_chest.InsertAllOnSubmit(chests);
            data.SubmitChanges();
        }
        private void HeightInsert(DataTable dt)
        {
            var heights = HeightDataTableToList(dt);
            var heightversions = heights.Select(p => p.version).Distinct().ToList();
            if (heightversions.Count() != 1)
            {
                Alert.Show("Excel中存在多个版本，请修正");
                return;
            }
            var heightquery = data.standard_height.Where(p => p.version == heightversions[0]).ToList();
            data.standard_height.DeleteAllOnSubmit(heightquery);
            data.SubmitChanges();
            data.standard_height.InsertAllOnSubmit(heights);
            data.SubmitChanges();
        }
        private void WeightInsert(DataTable dt)
        {
            var weights = WeightDataTableToList(dt);
            var weightversions = weights.Select(p => p.version).Distinct().ToList();
            if (weightversions.Count() != 1)
            {
                Alert.Show("Excel中存在多个版本，请修正");
                return;
            }
            var weightquery = data.standard_weight.Where(p => p.version == weightversions[0]).ToList();
            data.standard_weight.DeleteAllOnSubmit(weightquery);
            data.SubmitChanges();
            data.standard_weight.InsertAllOnSubmit(weights);
            data.SubmitChanges();
        }
        private void LungsInsert(DataTable dt)
        {
            var lungs = LungsDataTableToList(dt);
            var lungversions = lungs.Select(p => p.version).Distinct().ToList();
            if (lungversions.Count() != 1)
            {
                Alert.Show("Excel中存在多个版本，请修正");
                return;
            }
            var lungquery = data.standard_lungs.Where(p => p.version == lungversions[0]).ToList();
            data.standard_lungs.DeleteAllOnSubmit(lungquery);
            data.SubmitChanges();
            data.standard_lungs.InsertAllOnSubmit(lungs);
            data.SubmitChanges();
        }
        private void PulsationInsert(DataTable dt)
        {
            var pulsations = PulsationDataTableToList(dt);
            var pulsationversions = pulsations.Select(p => p.version).Distinct().ToList();
            if (pulsationversions.Count() != 1)
            {
                Alert.Show("Excel中存在多个版本，请修正");
                return;
            }
            var pulsationquery = data.standard_pulsation.Where(p => p.version == pulsationversions[0]).ToList();
            data.standard_pulsation.DeleteAllOnSubmit(pulsationquery);
            data.SubmitChanges();
            data.standard_pulsation.InsertAllOnSubmit(pulsations);
            data.SubmitChanges();
        }
        private void NutritionInsert(DataTable dt)
        {
            var nutritions = NutritionDataTableToList(dt);
            var nutritionversions = nutritions.Select(p => p.version).Distinct().ToList();
            if (nutritionversions.Count() != 1)
            {
                Alert.Show("Excel中存在多个版本，请修正");
                return;
            }
            var nutritionquery = data.standard_nutrition.Where(p => p.version == nutritionversions[0]).ToList();
            data.standard_nutrition.DeleteAllOnSubmit(nutritionquery);
            data.SubmitChanges();
            data.standard_nutrition.InsertAllOnSubmit(nutritions);
            data.SubmitChanges();
        }
        protected void btnsubmit_Click(object sender,EventArgs e)
        {
            String stardar = this.ddlstar.SelectedValue;
            var dt=ViewState["stardardata"] as DataTable;
            String fileName = txtimport.FileName;
            try
            {
                switch (stardar)
                {
                    case "height":
                        if (fileName.Contains("身高"))
                        {
                            HeightInsert(dt);
                            Alert.Show("身高标准升级成功");
                        }
                        else
                        {
                            Alert.Show("请确保你将导入的是身高标准，且文件名为身高标准！");
                        }
                        break;
                    case "weight":
                        if (fileName.Contains("体重"))
                        {
                            WeightInsert(dt);
                            Alert.Show("体重标准升级成功");
                        }
                        else
                        {
                            Alert.Show("请确保你将导入的是体重标准，且文件名为体重标准！");
                        }
                        break;
                    case "chest":
                        if (fileName.Contains("胸围"))
                        {
                            ChestInsert(dt);
                            Alert.Show("胸围标准升级成功");
                        }
                        else
                        {
                            Alert.Show("请确保你将导入的是胸围标准，且文件名为胸围标准！");
                        }
                        break;
                    case "lungs":
                        if (fileName.Contains("肺活量"))
                        {
                            LungsInsert(dt);
                            Alert.Show("肺活量标准升级成功");
                        }
                        else
                        {
                            Alert.Show("请确保你将导入的是肺活量标准，且文件名为肺活量标准！");
                        }
                        break;
                    case "pulsation":
                        if (fileName.Contains("脉搏"))
                        {
                            PulsationInsert(dt);
                            Alert.Show("脉搏标准升级成功");
                        }
                        else
                        {
                            Alert.Show("请确保你将导入的是脉搏标准，且文件名为脉搏标准！");
                        }
                        break;
                    case "nutrition":
                        if (fileName.Contains("营养"))
                        {
                            NutritionInsert(dt);
                            Alert.Show("营养标准升级成功");
                        }
                        else
                        {
                            Alert.Show("请确保你将导入的是营养标准，且文件名为营养标准！");
                        }
                        break;

                }
            }
            catch(Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
    }
}